package com.cn.sender;

import com.cn.config.SenderConf;
import com.cn.sender.processor.ExpirationMessagePostProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class RabbitMqDelaySender {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    /**
     * @param msg
     * @param expiration 过期时间
     */
    public void Send(String msg, String expiration) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        log.info("延迟发送队列，开始打印时间：{}", sdf.format(new Date()));
        msg += "发送时间"+sdf.format(new Date());
        this.rabbitTemplate.convertAndSend(SenderConf.DELAY_QUEUE_PER_QUEUE_TTL_NAME, (Object) msg
                , new ExpirationMessagePostProcessor(expiration));
    }
}
